package domain

import (
	"album/dao"
	"album/model"
	"album/repo"
	"context"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
	"listenboos-common/db"
)

type OrderInfoDomain struct {
	orderInfoRepo repo.OrderInfoRepo
}

func (u *OrderInfoDomain) Save(ctx context.Context, conn db.DBConn, data []*model.OrderInfo) error {
	err := u.orderInfoRepo.Save(ctx, conn, data)
	if err != nil {
		logx.Error(err)
		return errors.New("数据库异常")
	}
	return nil
}
func (u *OrderInfoDomain) FindByAid(ctx context.Context, orderNo string) ([]*model.OrderInfo, error) {
	orderInfo, err := u.orderInfoRepo.FindByAid(ctx, orderNo)
	if err != nil {
		logx.Error(err)
		return nil, errors.New("数据库异常")
	}
	return orderInfo, nil
}
func (u *OrderInfoDomain) DeleteOrderInfos(ctx context.Context, conn db.DBConn, orderNo string) error {
	err := u.orderInfoRepo.DeleteOrderInfos(ctx, conn, orderNo)
	if err != nil {
		logx.Error(err)
		return errors.New("数据库异常")
	}
	return nil
}
func NewOrderInfoDomain(db *db.ListenDB) *OrderInfoDomain {
	return &OrderInfoDomain{
		orderInfoRepo: dao.NewOrderInfoDao(db),
	}
}
